var app = angular.module('updateMerApp',['ui.bootstrap']);
    app.controller('updateMerCtrl',function($scope, $rootScope, $modal){
        var merchant={};
        
        $scope.open = function () {
            var modalInstance = $modal.open({
                templateUrl: 'updateMerContent.html',
                controller: 'updateModalCtrl',
                resolve: {
                    merchant:function(){
                        return merchant;
                    }
                }
            });
        };
    });
    app.controller('updateModalCtrl', function ($scope, $modalInstance, merchant) {
          $scope.merchant={
                username:'JOEL',
                password:'1234',
                address:'ZHA'
            };
        
        //  $scope.alerts = [
        //         { type: 'danger', msg: '失败' },
        //         ]
        $scope.submitForm = function () {
        // $scope.closeAlert = function(index) {
        // $scope.alerts.splice(index, 1);
        // };
            if($scope.updateForm.$invalid){
                alert('更改失败，请检查你的信息是否正确')        
        
            }
		    else{
			    var merchant = {
                merchant_name:merchant.username,
                password:merchant.password,
                address:merchant.address
                };
            $http({
                method: 'put',
                url: '/amc_m/mer/update',
                data:merchant
            }).then(function successCallback(response) {
                // 请求成功
                $scope.merchant= response.data;
            }, function errorCallback(response) {
                // 请求失败执行代码
            });
             $modalInstance.close();
            }
            
           
        };
        $scope.cancel = function () {
            $modalInstance.dismiss('cancel');
        };
    });

    app.directive('compare', function(){
	return {
	
	strict : 'AE',
	scope : {
			orgText: '=compare'
	},
	
	require : 'ngModel',
	link : function(sco,ele,att,con){
		con.$validators.compare=function(v) {
			return v == sco.orgText;	
		};
	    sco.$watch('orgText',function(){
			con.$validate();
		});
        }
	};
});